"""author:qinyu
   data: 2021/11/23
   project: cjh
"""
# import random
#
# def getRandomSet(bits):
#     nums = [chr(i) for i in range(48, 58)]
#     chars = [chr(i) for i in range(97, 123)]
#     counts = nums + chars
#     value_set = "".join(random.sample(counts, bits))
#     return value_set
#
# with open("D:\cjh\passwd.txt",'w+') as f:
#     n = input("请输入您想随机生成几个激活码: ")
#     if n.isdigit():
#         n = int(n)
#         for x in range(0, n):
#             if __name__ == '__main__':
#                 passwords = getRandomSet(32)
#                 f.writelines(passwords)
#                 f.writelines('\n')
#                 print(f"已经生成{x+1}个激活码")
#     else:
#         print("输入不是数字，不合法！")

import subprocess
from IPy import IP
try:
    nums = input("请您要检查的网段、子网掩码：")
    ip = IP(nums)
    for i in ip:
        segment = subprocess.call(f'ping -c 1 {i}',shell=True)
        if segment == 0:
            with open('segmentsused.txt', 'a+', encoding="utf-8")as fp:
                fp.write(f'{i}已被使用\n')
        elif segment == 1:
            with open('segmentsunused.txt', 'a+',encoding="utf-8")as fp:
                fp.write(f'{i}未被使用\n')
except Exception:
    print('错误！')


